package dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;

import connectUtil.ConnectionUtil;

import entity.Visitor;

public class LoginDAO {
	private static Connection conn;
    private static CallableStatement callProc;
    private static ResultSet rs;
    
    public static Visitor checkVisistor(Visitor visitor) {
    	try {
    		conn = ConnectionUtil.getConnection();
    		callProc = conn.prepareCall("{call checkVisitor(?, ?)}");
    		callProc.setString(1, visitor.getUserName());
    		callProc.setString(2, visitor.getPassword());    		
    		rs = callProc.executeQuery();
    		
    		while (rs.next()) {
    			System.out.println(" co du lieu roi !");
    			visitor.setId(rs.getInt("id"));
    			visitor.setUserName(rs.getString("userName"));
    			visitor.setPassword(rs.getString("password"));
    			visitor.setFirstName(rs.getString("firstName"));
    			visitor.setLastName(rs.getString("lastName"));
    			visitor.setGender(rs.getString("gender"));
    			visitor.setTelephone(rs.getString("telephone"));
    			visitor.setEmail(rs.getString("email"));
    			visitor.setArea(rs.getString("area"));
    			visitor.setHobby(rs.getString("hobby"));
    			visitor.setDescription(rs.getString("description"));
    			visitor.setRole(rs.getBoolean("role"));
    		}
    		System.out.println(" " + visitor.getUserName());
    	} catch (Exception ex) {
    		System.out.println(ex.getMessage());
    	}
    	return visitor;
    }
}
